package com.sunday.android.fangdaifu.bukong.utils.noticeview;

import android.os.Handler;
import android.widget.TextView;

import com.sunday.android.fangdaifu.bukong.entity.IndexTop;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/28.
 */
public class NoticeShowUtils {
    private List<IndexTop.ListBean> mDataList = new ArrayList<IndexTop.ListBean>();
    private TextView mNoticeTextView;
    private NoticeAdapter mNoticeAdapter;
    private NoticeView mNoticeView;
    private Handler mHandler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    int index = msg.arg1 + 1;
                    if (index >= mDataList.size()) {
                        index = 0;
                    }
                    mNoticeTextView.setText(mDataList.get(index).getTitle());
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(1, index, 0), 2000);
                    break;
                default:
                    break;
            }
        };
    };

    public NoticeShowUtils(){}

    public NoticeShowUtils(NoticeView mNoticeView,List<IndexTop.ListBean> mDataList) {
        if(mDataList==null || mDataList.isEmpty()){
            mDataList.add(new IndexTop.ListBean());
        }
        mNoticeAdapter = new NoticeAdapter(mDataList);
        mNoticeView.setAdapter(mNoticeAdapter);
        // 开启线程滚动
        mNoticeView.start();
    }
    /**
     * 直接通过设置textview达到公告显示的效果
     */
    private void getNotices(NoticeView mNoticeView,TextView showOne,List<IndexTop.ListBean> mDataList) {
        if (mDataList.size() > 0) {
            mNoticeTextView.setText(mDataList.get(0).getTitle());
            mHandler.sendMessageDelayed(mHandler.obtainMessage(1, 0, 0), 2000);
        }
    }
}
